 

import java.util.ArrayList;

/**
 * Subclass to Associate
 * @author Stefan
 */

public class Employee extends Associate
{
    //Attributes
    private ArrayList<Trade> trades;

    public Employee(String id, String name, String address, String company)
    {
        super(id, name, address, company);
        this.trades = new ArrayList();
    }

    public void addTrade(Trade trade)
    {
        trades.add(trade);
    }

    public void deleteTrade(Trade trade)
    {
        trades.remove(trade);
    }

    /**
     * Get all trades of Employee
     * @return ArrayList with trades
     */
    public ArrayList<Trade> getTrades()
    {
        return trades;
    }

    /**
     * Find trade by id
     * @param id
     * @return Trade
     */
    public Trade findTradeID(String id)
    {
        Trade found = null;
        for(Trade trade : trades)
        {
            if (trade.getId().equals(id))
            {
                found = trade;
            }
        }
        return found;
    }

    /**
     * Get number of sales
     * @return number of sales
     */
    public int numberOfSales()
    {
        return trades.size();
    }

    /**
     * Get total sold of all sales
     * @return total sold amount
     */
    public double getTotalSold()
    {
        double total = 0;
        for (Trade trade : trades)
        {
            total += trade.totalPrice();
        }
        return total;
    }

    /**
     * Get average total of all sales
     * @return average sale total
     */
    public double averageOfAllSales()
    {
       return numberOfSales() / getTotalSold();
    }
}
